//当前主题状态库
import { defineStore } from 'pinia'

/**
 * 主题状态库
 */
export const useThemeStore = defineStore('theme', {
    state: () => ({
        theme: 'light',
        isDark: false,
        isLight: false,
        breadcrumbs: [
            {
                path: '/',
                title: '首页'
            }
        ]
    }),
    actions: {
        setTheme(theme) {
            this.theme = theme
        },
        setIsDark(isDark) {

        },
        setBreadcrumbs(to) {

            const parentRoutes = to.matched.filter(r=>r.path !== '/').map(record => ({
                path: record.path,
                name: record.name,
                meta: record.meta ? {...record.meta} : null, // 浅拷贝meta避免修改原对象
            }));

            this.breadcrumbs = []
            this.breadcrumbs = parentRoutes.map(item => {
                return {
                    path: item.path,
                    title: item.meta.title,
                }
            })
        }
    }
})